package cn.echoedu.specifics;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.echoedu.daoconstants.TableName;
import cn.echoedu.entity.HomePageImage;
import cn.echoedu.entity.Image;
import cn.echoedu.entity.School;

public class SpecHomePageImage extends BaseSpec{

	@Override
	public <T> PreparedStatement getPreparedInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		HomePageImage homepageimage=(HomePageImage)currentPojo;
		String sql="insert into homepageimage(homepageimageid,showinhomepage,publishtime," +
				"schoolcode,imagetourl) values(?,?,?,?,?)";
		PreparedStatement preparedstatement=con.prepareStatement(sql);
		preparedstatement.setInt(1,homepageimage.getHomepageimageid());
		preparedstatement.setInt(2,homepageimage.getShowinhomepage());
		preparedstatement.setDate(3,(Date) homepageimage.getPublishtime());
		preparedstatement.setInt(4,homepageimage.getSchool().getSchoolcode());
		preparedstatement.setString(5,homepageimage.getImagetourl());

		return preparedstatement;
	}

	@Override
	public <T> PreparedStatement getPreparedInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		HomePageImage homepageimage=(HomePageImage)currentPojo;
		String sql="insert into homepageimage(showinhomepage,publishtime," +
				"schoolcode,imagetourl) values(?,?,?,?)";
		PreparedStatement preparedstatement=con.prepareStatement(sql);
		preparedstatement.setInt(1,homepageimage.getShowinhomepage());
		preparedstatement.setDate(2,(Date) homepageimage.getPublishtime());
		preparedstatement.setInt(3,homepageimage.getSchool().getSchoolcode());
		preparedstatement.setString(4,homepageimage.getImagetourl());
		return preparedstatement;
	}

	@Override
	public Object getPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub

		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedUpdate(Connection con,
			TableName tableName, T oldPojo, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getLeftJoinPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		HomePageImage homepageimage=new HomePageImage();
		homepageimage.setHomepageimageid(rs.getInt("homepageimageid"));
		homepageimage.setShowinhomepage(rs.getInt("showinhomepage"));
		School school=new School();
		try{
			school.setSchoolcode(rs.getInt("schoolcode"));
			homepageimage.setSchool(school);
			homepageimage.setImagetourl(rs.getString("imagetourl"));
		}catch(Exception e){
			e.printStackTrace();
		}
		Image image=new Image();
		try{
			image.setImageid(rs.getInt("imageid"));
			image.setImagename(rs.getString("imagename"));
			image.setImagesrc(rs.getString("imagesrc"));
		}catch(Exception e){
			e.printStackTrace();
		}
		homepageimage.setImage(image);
		return homepageimage;
	}

	@Override
	public Object getPojoBySql(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> String getPreparedInsertGetPrimaryKeySql(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
